<template>
  <el-container style="height: 100%">
    <el-menu
      :default-active="activeIndex"
      class="el-menu-demo"
      mode="horizontal"
      @select="getCurrentIndex"
      @click="flush"
      background-color="#545652"
      text-color="#d5d5d5"
      active-text-color="#fdfdfd"
    >
      <el-menu-item index="home">图书搜索</el-menu-item>
      <el-menu-item index="Pic">图片</el-menu-item>
      <el-menu-item index="Video">视频</el-menu-item>
      <el-menu-item index="person" v-if="isManager">上传文件</el-menu-item>
      <el-menu-item style="float: right">
        <el-link type="danger" @click="sign_out">退出</el-link>
      </el-menu-item>
    </el-menu>
    <router-view />
    <el-footer style="background: #545652; height: 30px; bottom: 0">
      <el-row>
        <el-col>
          <div style="text-align: center; font-size: small;padding-top: 5px">
            <span
              ><a
                href="http://xxxy.lzu.edu.cn/jigoushezhi/xisuoshezhi/2020/1014/139911.html"
                style="color: #fdfdfd; text-decoration: none"
                >关于我们</a
              ></span
            >
            <el-divider direction="vertical"></el-divider>
            <span
              ><a
                href="http://history.lzu.edu.cn/portal/article/index/id/223.html"
                style="color: #fdfdfd; text-decoration: none"
                >联系我们</a
              ></span
            >
          </div>
        </el-col>
      </el-row>
    </el-footer>
  </el-container>
</template>

<script>
import store from "@/store";

export default {
  name: "Main",
  data() {
    return {
      activeIndex: "1",
      isManager: 0
    };
  },
  methods: {
    flush() {
      // console.log('click');
      location.reload();
    },
    getCurrentIndex(item) {
      // console.log("Main index:" + item);
      if (item === "home") {
        this.$router.push({ name: "Home" });
      } else if (item === "person") {
        this.$router.push({ name: "PersonalPage" });
      } else if (item === "Pic") {
        this.$router.push({ name: "Pic" });
      } else if (item === "Video") {
        this.$router.push({ name: "Video" });
      }
    },
    sign_out() {
      store.commit("signOut");
    }
  },
  created() {
    this.isManager = store.getters.userInfo.isManager;
    // console.log('isManager', this.isManager);
    if (this.$router.currentRoute.value.name === "Main") {
      this.$router.push({ name: "Home" });
    }
  }
};
</script>

<style scoped></style>
